# 6）房源类型（条形图）【一室、两室、三室等的数量】
import pandas as pd
from pyecharts.charts import Bar
from pyecharts.globals import ThemeType
df = pd.read_excel('data_clean.xlsx')
location_list = []
for location in df['type']:
    location = location[0:1]
    location_list.append(location)
df['location'] = location_list
locations = [location for location in df['location'].value_counts().items()]
x_data =[]
y_data = []
for i in range(len(locations)):
    x_data.append(locations[i][0])
    y_data.append(locations[i][1])

c = (
    Bar({"theme": ThemeType.MACARONS})
    .add_xaxis(x_data)
    .add_yaxis("房源", y_data)

    .set_global_opts(
        title_opts={"text": "房源类型", "subtext": ""}
    )
    .render("条形图.html")
)